package com.heny.demo.tools;

import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Point;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;

public class CoordinateTransformUtil {
    public static Point transformPoint(Point point, String sourceCRS, String targetCRS) throws Exception {
        // 解析源坐标系和目标坐标系
        CoordinateReferenceSystem sourceCRSObj = CRS.decode(sourceCRS);
        CoordinateReferenceSystem targetCRSObj = CRS.decode(targetCRS);

        // 创建坐标转换对象
        MathTransform transform = CRS.findMathTransform(sourceCRSObj, targetCRSObj, false);

        // 转换坐标
        return (Point) JTS.transform(point, transform);
    }
}